package com.ming.mallchat.common.chat.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ming.mallchat.common.chat.mapper.RoomFriendMapper;
import com.ming.mallchat.common.chat.pojo.RoomFriend;
import com.ming.mallchat.common.common.domain.enums.NormalOrNoEnum;
import org.springframework.stereotype.Service;

@Service
public class RoomFriendDao extends ServiceImpl<RoomFriendMapper, RoomFriend> {

    public RoomFriend getByKey(String key) {
        return lambdaQuery().eq(RoomFriend::getRoomKey,key).one();
    }

    public void restoreRoom(Long id) {
        lambdaUpdate().eq(RoomFriend::getId,id).set(RoomFriend::getStatus, NormalOrNoEnum.NORMAL.getStatus()).update();
    }

    public void disableRoom(String key) {
        lambdaUpdate().eq(RoomFriend::getRoomKey,key).set(RoomFriend::getStatus,NormalOrNoEnum.NOT_NORMAL.getStatus());
    }

    public RoomFriend getRoomId(Long roomId) {
        return lambdaQuery()
                .eq(RoomFriend::getRoomId,roomId)
                .one();
    }
}
